﻿using Sidvall.CodeGenerator.Collections;
using System.Collections.Generic;

namespace Sidvall.CodeGenerator
{
    public class ResourceFileImportSettings
    {
        #region Public Members

        public string ExcludePrefixes { get; set; }
        public ResourceFileCollection ResourceFiles { get; private set; }

        public bool IsExcluded(string name)
        {
            foreach (var excludePrefix in this.ExcludePrefixIndex)
            {
                if (name.StartsWith(excludePrefix, System.StringComparison.OrdinalIgnoreCase))
                    return true;
            }
            return false;
        }

        #endregion
        #region Private Members

        #region ExcludePrefixIndex

        private HashSet<string> _ExcludePrefixIndex;
        private HashSet<string> ExcludePrefixIndex
        {
            get
            {
                if (_ExcludePrefixIndex == null)
                {
                    var items = this.ExcludePrefixes.Split("|", System.StringSplitOptions.RemoveEmptyEntries);
                    _ExcludePrefixIndex = items.ToHashSet(o => o, true);
                    if (_ExcludePrefixIndex == null)
                        _ExcludePrefixIndex = new HashSet<string>();
                }
                return _ExcludePrefixIndex;
            }
        }

        #endregion

        #endregion
        #region Constructors

        public ResourceFileImportSettings()
        {
            this.ExcludePrefixes = string.Empty;
            this.ResourceFiles = new ResourceFileCollection();
        }

        #endregion
    }
}
